from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from cemberus.html_meta.models import HtmlMeta, DateMeta
from cemberus.categories.models import Category


class Project(HtmlMeta, DateMeta, models.Model):
    user = models.ForeignKey(User, verbose_name = _('Benutzername'))
    category = models.ForeignKey(Category, verbose_name = _('Kategorie'))
    
    STATUS_CHOICES = (
        (10, _(u'Normal')),
        (20, _(u'Featured')),
    )
    
    # required fields
    name = models.CharField(verbose_name = _('Name'), max_length = 120)
    slug = models.SlugField(verbose_name = _('URL'), max_length = 120, unique = True)
    description = models.TextField(verbose_name = _('Beschreibung'))
    status = models.CharField(verbose_name = _('Projektstatus'), max_length = 2, choices = STATUS_CHOICES, default = 10)
    
    # extra fields
    image = models.ImageField(verbose_name = _('Projektlogo'), upload_to = 'projekte/logos', null = True, blank = True)
    homepage = models.URLField(verbose_name = _('Projektseite'), verify_exists = False, null = True, blank = True)
    email = models.EmailField(verbose_name = _('Kontaktadresse'), max_length = 80, null = True, blank = True)
    
    def __unicode__(self):
        return self.name
        
    def get_absolute_url(self):
        return ('projects_detail', (), {'slug': self.slug})
    get_absolute_url = models.permalink(get_absolute_url)
    
    class Meta:
        verbose_name = _(u'Projekt')
        verbose_name_plural = _(u'Projekte')
        
